// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
// element UI
import ElementUI from 'element-ui'; //引入核心js组件
import 'element-ui/lib/theme-chalk/index.css';//引入依赖的样式
// 背景粒子特效
import VueParticles from 'vue-particles'
import axios from './axios'
import store from './store';
import validators  from './common/js/validators.js'

Vue.prototype.validators = validators
Vue.prototype.$axios = axios
Vue.use(VueParticles)
Vue.use(ElementUI)
Vue.config.productionTip = false

// 导航守卫
// 使用 router.beforeEach 注册一个全局前置守卫，判断用户是否登陆
router.beforeEach((to, from, next) => {
  if (to.path === '/' || to.path === '/login') {
    next();
  } else {
    let token = localStorage.getItem('Authorization');
    console.log("我是浏览器本地缓存的token:"+token);
    if (token === null || token === '') {
      next({path:"/"});
      alert("尚未登录!!");
    } else {
      next();
    }
  }
})

new Vue({
  el: '#app',
  router,
  store:store,
  components: { App },
  template: '<App/>'
})
